/*
 *  untitled.cpp
 *  SpaceTrader
 *
 *  Created by Andrew on 10/17/12.
 *  Copyright 2012 The Hex Pistols. All rights reserved.
 *
 */

#include "Universe.h"
#include <iostream>

Universe::Universe() : systems(std::vector<System*>()){
    
}
Universe::Universe(Market *market) : systems(std::vector<System*>())
{
    std::vector<Planet*> v1;
	std::vector<Planet*> v2;
	std::vector<Planet*> v3;
    
	//Names are shamelessly ripped from the Mass Effect Universe
	v1.push_back(new Planet("Gorgon", 50, 70, load_image("GuiButton.png", false), market));
	v1.push_back(new Planet("Hydra", 150, 370, load_image("GuiButton.png", false), market));
	v1.push_back(new Planet("Phoenix", 400, 150, load_image("GuiButton.png", false), market));
	
	v2.push_back( new Planet("Gagarin", 50, 70, load_image("GuiButton.png", false), market));
	v2.push_back( new Planet("Grissom", 460, 400, load_image("GuiButton.png", false), market));
	v2.push_back( new Planet("Hong", 80, 300, load_image("GuiButton.png", false), market));
	v2.push_back( new Planet("Tereshkova", 330, 160, load_image("GuiButton.png", false), market));
	v2.push_back( new Planet("Vamshi", 160, 240, load_image("GuiButton.png", false), market));
	
	v3.push_back( new Planet("Lucrum Primaris", 50, 70, load_image("GuiButton.png", false), market));
	v3.push_back( new Planet("Lucrum Secundus", 460, 400, load_image("GuiButton.png", false), market));
	v3.push_back( new Planet("Lucrum Tertius", 80, 300, load_image("GuiButton.png", false), market));
	v3.push_back( new Planet("Lucrum Quaternus", 330, 160, load_image("GuiButton.png", false), market));
	v3.push_back( new Planet("Lucrum Quintus", 160, 240, load_image("GuiButton.png", false), market));

	systems.push_back(new System("Argos Rho", 130, 300, v1, load_image("GuiButton.png", false)));
	systems.push_back(new System("Armstrong Nebula", 350, 180, v2,load_image("GuiButton.png", false)));
	systems.push_back(new System("Lucrum", 450, 420, v3,load_image("GuiButton.png", false)));

	for (unsigned int i = 0; i < systems.size(); i++) {
		std::vector<Planet*> planets = systems[i]->getPlanets();
		//std::cout << "Planets in system "
		//<< systems[i]->getName() << std::endl;
//		for (unsigned int j = 0; j < planets.size(); j++) {
//			std::cout << "    " << planets[j]->getName()
//			<< std::endl << "        "
//			<< " Tech Level: " << planets[j]->getTechLevel() 
//			<< std::endl << "        "
//			<< " Resources: " << planets[j]->getResources() 
//			<< std::endl ; 
//		}
//		std::cout << std::endl;
	}
}

Universe::~Universe() {
	for (unsigned int i = 0; i < systems.size(); i++ ) {
		std::vector<Planet*> planets = systems[i]->getPlanets();
		for (unsigned int j = 0; j < planets.size(); j++) {
			free(planets[j]);
		}
		free(systems[i]);
	}
}

std::vector<System*> Universe::getSystems() {
	return systems;
}
